<template>
	<view class="content">
		<!-- 背景图 -->
		<view class="wh-w750" style=" position: relative;">
			<image :src="nImg" mode="aspectFill" style="height: 1338rpx; width: 750rpx;"></image>
		</view>
		<view class="footer">
			<view class="share-container">
				<!-- 圆形分享按钮 -->
				<view class="share-button" :class="{'active': isAnimating}">
					<!-- 分享图标 -->
					<view class="share-icon">
						<button open-type="share" class="hide-button-style">
							<image src="../../static/1.png" mode=""></image>
						</button>
					</view>
					<!-- 扩散动画效果 -->
					<view class="pulse-ring" v-for="(ring, index) in 3" :key="index"
						:style="{ animationDelay: `${index * 0.3}s` }">
					</view>
				</view>
				<!-- 分享文字 -->
				<text class="share-text">分享好友来一发</text>
			</view>
		</view>
		<!-- 转盘 -->
		<view class="luck-list" style="position: absolute;top: 415rpx;right: 0;left: 72rpx; width: 600rpx;">
			<view v-for="(item,index) in AwardList" :key="index">
				<view class="cell-item" :class="index==4||index===sel?'y-b':'w-b'" @tap="begin(index)">
					<view class="cell-content" :class="index==4||index===sel?'y':'w'">
						<image :src="item.image" mode="widthFix" style="width: 60rpx; height: 60rpx;" v-if="item.image"></image>
						<view style="margin-top: 5rpx;">
							<text style="font-size: 21rpx; font-weight: bold;">{{item.name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>

	
	</view>
</template>

<script>
	export default {
		props: {
			// 背景图
			nImg: String,
			// 列表
			AwardList: {
				type: Array,
				default: []
			},
			// 中奖索引
			sjNum: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				sel: '',
				FastNums: 0,
				SlowNums: 0,
				time: 1000,
				LoopStatus: true,
				noClick: true,
				isAnimating: false
			}
		},
		onLoad() {

		},
		onShow() {
			wx.showShareMenu({
				menus: ["shareAppMessage", "shareTimeline"]
			});
		},
		methods: {
			onShareAppMessage(res) {
				if (res.from === 'button') {
					return {
						title: "今天打不打飞机",
						imageUrl: 'https://youpindou.com:18877/static/lyf.jpg',
						path: `/pages/index/index`, // 带参数路径
					};
				}
			},
			// 中奖后的逻辑
			updateMoney(sjNum) {
				this.$emit('updateMoney', sjNum)
			},
			// 开始抽奖
			begin(index) {
				if (index == 4) {
					if (!this.noClick) {
						uni.showToast({
							title: '请勿频繁点击',
							icon: "none",
							position: 'bottom'
						});
						return
					};
					this.noClick = false;
					this.FastNums = 0
					this.SlowNums = 0
					this.time = 200
					this.LoopStatus = true
					this.loop()
				}
			},
			// 抽奖过程 控制
			loop() {
				let sjNum = this.sjNum
				console.log(sjNum)
				if (!this.sel || this.sel < 9) {
					if (this.sel == 3) {
						this.sel = 0
					} else if (this.sel === '') {
						this.sel = 0
					} else if (this.sel == 2) {
						this.sel = 5
					} else if (this.sel == 5) {
						this.sel = 8
					} else if (this.sel == 8) {
						this.sel = 7
					} else if (this.sel == 7) {
						this.sel = 6
					} else if (this.sel == 6) {
						this.sel = 3
					} else {
						this.sel++
					}
					this.FastNums++
					if (this.FastNums == 4) {
						this.FastNums = 0
						this.time = 50
						this.SlowNums++
					}
					if (this.SlowNums == 8) {
						this.SlowNums = 0
						this.time = 500
						this.FastNums = 5
					}
					if (this.FastNums > 5) {
						if (this.sel == sjNum) {
							this.noClick = true;
							this.LoopStatus = false
							// 成功的逻辑
							this.updateMoney(sjNum)
						}
					}
					if (this.LoopStatus) {
						setTimeout(() => {
							this.loop()
						}, this.time);
					}
				}
			}
		}

	}
</script>

<style scoped>
	.content {
		height: 100%;
		overflow: hidden;
	}

	/* 主容器 */
	.share-container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px;
	}

	/* 分享按钮 */
	.share-button {
		width: 60px;
		height: 60px;
		border-radius: 50%;
		background: linear-gradient(135deg, #FF9A9E 0%, #FAD0C4 100%);
		box-shadow: 0 6px 12px rgba(250, 208, 196, 0.5);
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		transition: transform 0.3s ease;
	}

	/* 按钮点击动画 */
	.share-button.active {
		transform: scale(0.9);
	}

	/* 分享图标 */
	.share-icon {
		z-index: 10;

	}

	.share-icon-img {
		width: 24rpx;
		height: 24rpx;
	}

	/* 扩散波纹效果 */
	.pulse-ring {
		position: absolute;
		width: 100%;
		height: 100%;
		border-radius: 50%;
		border: 2px solid #FF9A9E;
		opacity: 0;
		animation: pulse 1.5s infinite;
	}

	@keyframes pulse {
		0% {
			transform: scale(0.9);
			opacity: 0.8;
		}

		100% {
			transform: scale(1.5);
			opacity: 0;
		}
	}

	/* 分享文字 */
	.share-text {
		margin-top: 8px;
		font-size: 14px;
		color: #FF9A9E;
		font-weight: 500;
	}

	.footer {
		position: relative;
		top: -200rpx;
	}

	.hide-button-style {
		background-color: transparent !important;
		border: none !important;
		padding: 0 !important;
		margin: 0 !important;
		border-radius: 0 !important;
	}

	.hide-button-style::after {
		display: none !important;
	}

	/* 抽奖 */
	.luck-list {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-wrap: wrap;
	}

	.cell-item {
		width: 150rpx;
		height: 158rpx;
		border-radius: 30rpx;
		margin: 5rpx;
	}

	.cell-content {
		width: 150rpx;
		height: 138rpx;
		border-radius: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.w {
		background-color: #fdf2ee;
	}

	.w-b {
		background-color: #f8d0c3;
	}

	.y {
		background-color: #fee610;
	}

	.y-b {
		background-color: #EFCD22;
	}
</style>